package models;

import com.et.ar.ActiveRecordBase;
import com.et.ar.annotations.BelongsTo;
import com.et.ar.annotations.Column;
import com.et.ar.annotations.Id;
import com.et.ar.annotations.Table;
import com.et.ar.annotations.Unique;

import java.sql.*;

import utils.DateUtil;

//需求信息
@Table(name="demandinfo")
public class Demandinfo extends ActiveRecordBase{
	@Id private Integer id;
	@Column private String unitname;
	@Column private String z_id;
	@Column private Timestamp inputdate;
	@Column private Timestamp editdate;
	@Column private String op_mode;
	@Column private String op_type;
	@Column private String valid_time_hist;
	@Column private Timestamp valid_time;
	@Column private String address;
	@Column private String context;
	@Column private String memo;
	@Column private String oper;
	@Column private String mj;
	@Column private String tx;
	@Column private String lc;
	@Column private String jg;
	@Column private String zx;
	@Column private String lxfs;
	
	public Integer getTimeout(){
		
		Date fDate = new Date(System.currentTimeMillis()); 
		Date oDate = new Date(valid_time.getTime());
		
		return DateUtil.getIntervalDays(fDate, oDate);
	}

    public String getValid_time_hint(){
		
		switch (Integer.parseInt(valid_time_hist)){
		case 3:
			return "三天";
		case 7:
			return "一周";
		case 31:
			return "一月";
		case 91:
			return "三月";
		case 182:
			return "半年";
		case 365:
			return "一年";
		default:
			return "三天";
		}
	}
	//	@BelongsTo(foreignKey="demoId")
	//	private Demo demo;

	//	public Demo getDemo() {
	//		return demo;
	//	}
	//	public void setDemo(Demo demo) {
	//		this.demo = demo;
	//	}

	//	public int getChildCount() throws Exception {
	//		return (int)count(Demandinfo.class, "parentId=?", new Object[]{id});
	//	}
	//	public String findChildIds() throws Exception {
	//		String s = "";
	//		List<Integer> ids = new ArrayList<Integer>();
	//		ids.add(id);
	//		while(!ids.isEmpty()){
	//			int id = ids.remove(0);
	//			s += id + ",";
	//			for(Demandinfo item: Demandinfo.findAll(Demandinfo.class, "parentId=?", new Object[]{id})){
	//				ids.add(item.getId());
	//			}
	//		}
	//		if (!s.equals("")){
	//			s = s.substring(0, s.length() - 1);
	//		}
	//		return s;
	//	}
	public void setId(Integer id){
		this.id=id;
	}
	public Integer getId(){
		return id;
	}

	public void setUnitname(String unitname){
		this.unitname=unitname;
	}
	public String getUnitname(){
		return unitname;
	}

	public void setZ_id(String z_id){
		this.z_id=z_id;
	}
	public String getZ_id(){
		return z_id;
	}

	public void setInputdate(Timestamp inputdate){
		this.inputdate=inputdate;
	}
	public Timestamp getInputdate(){
		return inputdate;
	}

	public void setEditdate(Timestamp editdate){
		this.editdate=editdate;
	}
	public Timestamp getEditdate(){
		return editdate;
	}

	public void setOp_mode(String op_mode){
		this.op_mode=op_mode;
	}
	public String getOp_mode(){
		return op_mode;
	}

	public void setOp_type(String op_type){
		this.op_type=op_type;
	}
	public String getOp_type(){
		return op_type;
	}

	public void setValid_time_hist(String valid_time_hist){
		this.valid_time_hist=valid_time_hist;
	}
	public String getValid_time_hist(){
		return valid_time_hist;
	}

	public void setValid_time(Timestamp valid_time){
		this.valid_time=valid_time;
	}
	public Timestamp getValid_time(){
		return valid_time;
	}

	public void setAddress(String address){
		this.address=address;
	}
	public String getAddress(){
		return address;
	}

	public void setContext(String context){
		this.context=context;
	}
	public String getContext(){
		return context;
	}

	public void setMemo(String memo){
		this.memo=memo;
	}
	public String getMemo(){
		return memo;
	}

	public void setOper(String oper){
		this.oper=oper;
	}
	public String getOper(){
		return oper;
	}

	public void setMj(String mj){
		this.mj=mj;
	}
	public String getMj(){
		return mj;
	}

	public void setTx(String tx){
		this.tx=tx;
	}
	public String getTx(){
		return tx;
	}

	public void setLc(String lc){
		this.lc=lc;
	}
	public String getLc(){
		return lc;
	}

	public void setJg(String jg){
		this.jg=jg;
	}
	public String getJg(){
		return jg;
	}

	public void setZx(String zx){
		this.zx=zx;
	}
	public String getZx(){
		return zx;
	}

	public void setLxfs(String lxfs){
		this.lxfs=lxfs;
	}
	public String getLxfs(){
		return lxfs;
	}

}

